package com.googlecode.familytreesimulator;

import java.util.ArrayList;
import java.util.List;

/** Child creates and modifies Child object
 * 
 */
public class Child extends Human implements IProcreation{
	
	/* The mother genes */
	private String motherEyeColor;
	private String motherHeight;
	private String motherHairColor;
	private String motherHairType;
	private String motherSkinTone;
	
	/* The father genes */
	private String fatherHeight;
	private String fatherEyeColor;
	private String fatherHairColor;
	private String fatherHairType;
	private String fatherSkinTone;
	
	/* Array List for mother, father, and child */
	ArrayList<String> motherTraits = new ArrayList<String>();
	ArrayList<String> fatherTraits = new ArrayList<String>();
	ArrayList<String> childTraits = new ArrayList<String>();
	
	/** Child(String newFamilyMember) creates Child
	 *  object with a chosen family member field
	 * 
	 * @param newFamilyMember
	 */
	public Child(String newFamilyMember){
		super(newFamilyMember);
		this.familyMember = newFamilyMember;
	}
	
	/** importMotherGenes(ArrayList<String> geneList)
	 *  imports the mother's genes to be used by the
	 *  Child
	 * 
	 * @param geneList
	 */
	public void importMotherGenes(ArrayList<String> geneList){
		for (int i=0; i < geneList.size(); i++)
		{
			motherTraits.add(geneList.get(i));
		}	
		
		motherEyeColor = geneList.get(0);
		motherHeight = geneList.get(1);
		motherHairColor = geneList.get(2);
		motherHairType = geneList.get(3);
		motherSkinTone = geneList.get(4);
		
	}

	/** importFatherGenes(ArrayList<String> geneList)
	 * imports the father's genes to be used by the
	 * Child
	 * 
	 * @param geneList
	 */
	public void importFatherGenes(ArrayList<String> geneList){
		for (int i=0; i < geneList.size(); i++)
		{
			fatherTraits.add(geneList.get(i));
		}
		
		fatherEyeColor = geneList.get(0);
		fatherHeight = geneList.get(1);
		fatherHairColor = geneList.get(2);
		fatherHairType = geneList.get(3);
		fatherSkinTone = geneList.get(4);
	}
	
	/** produceChild(ArrayList<String> motherTraits, ArrayList<String fatherTraits)
	 *  sets the new child's genes based on the mother's traits
	 *  and father's traits
	 * 
	 * @param motherTraits, fatherTraits
	 */
	public void produceChild(ArrayList<String> motherTraits, ArrayList<String> fatherTraits){
		
				
		for (int i=0; i < motherTraits.size(); i++){
			double random = Math.random();
			
			if (random < .45){
				childTraits.add(i, motherTraits.get(i));
			}
			else if (random < .9){
				childTraits.add(i, fatherTraits.get(i));
			}
			else {	
				childTraits.add(getOtherTrait(i));	
			}
			
		}
		
		eyeColor = childTraits.get(0);
		height = childTraits.get(1);
		hairColor = childTraits.get(2);
		hairType = childTraits.get(3);
		skinTone = childTraits.get(4);
	}
	
	/** getOtherTrait(int index) retrieves another
	 *  trait from the GeneDatabase in the slight
	 *  chance that the Child does not inherit it's
	 *  traits from either Parent
	 * 
	 * @param index
	 * @return
	 */
	public String getOtherTrait(int index){
		GeneDatabase genes = new GeneDatabase();
		boolean isNewGene = false;
		String otherTrait = null;
		
		List<String> traitList = genes.getGeneList(index);
		while(isNewGene != true){
			int randomGene = (int) (Math.random()*traitList.size());
			
			if ((traitList.get(randomGene) != fatherEyeColor) && (traitList.get(randomGene) != motherEyeColor)){
				otherTrait = traitList.get(randomGene);
				isNewGene = true;
			}
		}
		
		return otherTrait;
	}

	/** printStats() prints the final Child traits
	 * 
	 */
	public void printStats(){
		System.out.println("\nMy eyes are " + eyeColor);
		System.out.println("I guess you can say I'm "
											+ height);
		System.out.println("My hair is " + hairColor
									+ " and " + hairType);
		System.out.println("And my skin is " + skinTone + "!\n");
	}
	
	/** getGenes() prints the genes that have been
	 *  inherited from either the mother, father,
	 *  neither Parent, or both Parent(s)
	 * 
	 */
	@Override
	public ArrayList<String> getGenes(){

		System.out.print("I have ");
		if(eyeColor.equals(motherEyeColor))
		{
			if(motherEyeColor.equals(fatherEyeColor))
				System.out.println("my parents' eyes.");
			else
				System.out.println("my mother's eyes.");
		}
		else if(eyeColor.equals(fatherEyeColor))
			System.out.println("my father's eyes.");
		else
			System.out.println("unique eyes.");

		
		System.out.print("I'm ");
		if(height.equals(motherHeight))
		{
			if(motherHeight.equals(fatherHeight))
				System.out.println("as tall as my parents.");
			else
				System.out.println("as tall as my mom.");
		}
			
		else if(height.equals(fatherHeight))
			System.out.println("as tall as my dad.");
		else
			System.out.println("a unique height.");

		
		
		System.out.print("My hair color is ");
		if(hairColor.equals(motherHairColor))
		{
			if(motherHairColor.equals(fatherHairColor))
				System.out.println("the same as my parents'.");
			else
				System.out.println("the same as my mom's.");
		}
		else if(hairColor.equals(fatherHairColor))
			System.out.println("the same as my dad's.");
		else
			System.out.println("unique.");

		
		
		System.out.print("My hair type is ");
		if(hairType.equals(motherHairType))
		{
			if(motherHairType.equals(fatherHairType))
				System.out.println("the same as my parents'.");
			else
				System.out.println("the same as my mom's.");
		}
		
		else if(hairType.equals(fatherHairType))
			System.out.println("the same as my dad's.");
		else
			System.out.println("unique.");

		
		
		System.out.print("My skin tone is ");
		if(skinTone.equals(motherSkinTone))
		{
			if(motherSkinTone.equals(fatherSkinTone))
				System.out.println("the same as my parents'.");
			else
				System.out.println("the same as my mom's.");
		}
		
		else if(skinTone.equals(fatherSkinTone))
			System.out.println("the same as my father's.");
		else
			System.out.println("unique.");

				
		return super.getGenes();
	}

}